package com.open.party.cloud.view.home.eJia

import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import cn.android.x.parent.AppTitleBaseActivity
import com.alibaba.fastjson.JSON
import com.open.party.cloud.R
import com.open.party.cloud.model.CommVo
import com.open.party.cloud.view.freePhoto.fragment.FreePhotosDoneListFragment
import com.open.party.cloud.view.freePhoto.fragment.FreePhotosFromMeListFragment
import com.open.party.cloud.view.freePhoto.fragment.FreePhotosUndoneListFragment
import com.open.party.cloud.view.home.eJia.fragment.*
import com.sinothk.android.utils.XUtils
import kotlinx.android.synthetic.main.title_tab_view_page_app_bg.*

class PartyLifeMainActivity : AppTitleBaseActivity() {

    override fun getLayoutResId(): Int = R.layout.title_tab_view_page_app_bg

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        initTabView()
    }

    private fun initTabView() {
        val titleList = ArrayList<String>()
        val fragmentList = ArrayList<Fragment>()

        titleList.add("党员大会")
        titleList.add("支委会")
        titleList.add("党小组会")
        titleList.add("党课")
        titleList.add("主题党日活动")
        titleList.add("党组织换届")
//        党员大会 支委会 党小组会 党课 主题党日活动 党组织换届
        fragmentList.add(PartyLife_DZBDH_ListFragment())
        fragmentList.add(PartyLife_ZBWYH_ListFragment())
        fragmentList.add(PartyLife_DXZH_ListFragment())
        fragmentList.add(PartyLife_DK_ListFragment())
        fragmentList.add(PartyLife_DRHD_ListFragment())
        fragmentList.add(PartyLife_DZZHJ_ListFragment())

        initTab(
            titleList,
            fragmentList
        )
    }

    private fun initTab(titles: ArrayList<String>, fragments: List<Fragment>) {

        val fragmentPagerAdapter = object : FragmentPagerAdapter(supportFragmentManager, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
            override fun getCount(): Int {
                return fragments.size
            }

            override fun getItem(arg0: Int): Fragment {
                return fragments[arg0]
            }
        }

        viewPager.offscreenPageLimit = titles.size - 1
        viewPager.adapter = fragmentPagerAdapter
        //        pager.addOnPageChangeListener(this);

        scrollTab.setTitles(titles)
//        scrollTab.setNumber(1, "9", View.VISIBLE)//设置数字红点
        scrollTab.setViewPager(viewPager)
        scrollTab.setOnTabListener { index, _ ->
            viewPager.setCurrentItem(index, true)
        }
    }

    fun setTitleRightView(extra: String) {
        if (XUtils.string().isNotEmpty(extra)) {
            val extraBean: CommVo = JSON.parseObject(extra, CommVo::class.java)
            if (extraBean.isAdmin) {
                setViewTitle("组织生活", "新增") {
                    XUtils.intent().openActivity(this, PartyLifeAddActivity::class.java).start()
                }
            } else {
                setViewTitle("组织生活")
            }
        }
    }
}

